﻿using dreamwork.membercenter.api.Services;
using DreamWork.WebAPI;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace dreamwork.membercenter.api.Controllers
{
	[Route("api/[controller]")]
	public class UserController : DreamWorkControllerBase
	{
		private readonly IMemberCenterService _memberCenterService;

		public UserController(IMemberCenterService memberCenterService)
		{
			_memberCenterService = memberCenterService;
		}

		[HttpPost, Route("[action]")]
		public async Task<IActionResult> AddUserAsync()
		{
			await _memberCenterService.AddUserAsync();
			return Ok("OK");
		}
		[HttpGet, Route("[action]")]
		public async Task<IActionResult> GetUserAsync()
		{
			var item = await _memberCenterService.GetUserAsync();
			return Ok(item);
		}
		[HttpPut, Route("[action]")]
		public async Task<IActionResult> UpdateUserAsync()
		{
			var item = await _memberCenterService.GetUserAsync();
			item.Email = DateTime.Now.ToString();
			await _memberCenterService.UpdateUserAsync(item);
			return Ok(item);
		}

		[HttpPost, Route("[action]")]
		public async Task<IActionResult> AddSomethingAsync()
		{
			await _memberCenterService.AddSomethingAsync();
			return Ok("OK");
		}
		[HttpGet, Route("[action]")]
		public async Task<IActionResult> GetSomethingAsync()
		{
			var item = await _memberCenterService.GetSomethingAsync();
			return Ok(item);
		}
		[HttpPut, Route("[action]")]
		public async Task<IActionResult> UpdateSomethingAsync()
		{
			var item = await _memberCenterService.GetSomethingAsync();
			item.Content = DateTime.Now.ToString();
			await _memberCenterService.UpdateSomethingAsync(item);
			return Ok(item);
		}
	}
}
